﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caifu.Datas;

namespace Caifu.Clients
{
	/// <summary>
	/// 每日净值
	/// </summary>
	public static class NetValueDailyClient
	{
		/// <summary>
		/// 添加每日净值
		/// </summary>
		/// <param name="netValueDaily"></param>
		public static void AddNetValueDaily(NetValueDaily netValueDaily)
		{
			NetValueDailyData.Instance.AddNetValueDaily(netValueDaily);
		}

		/// <summary>
		/// 添加每日净值
		/// </summary>
		/// <param name="netValueDailys"></param>
		public static void AddNetValueDailys(IList<NetValueDaily> netValueDailys)
		{
			foreach (var netValueDaily in netValueDailys)
			{
				AddNetValueDaily(netValueDaily);
			}
		}

		/// <summary>
		/// 修改每日净值
		/// </summary>
		/// <param name="netValueDaily"></param>
		public static void UpdateNetValueDaily(NetValueDaily netValueDaily)
		{
			NetValueDailyData.Instance.UpdateNetValueDaily(netValueDaily);
		}

		/// <summary>
		/// 修改每日净值
		/// </summary>
		/// <param name="netValueDailys"></param>
		public static void UpdateNetValueDailys(IList<NetValueDaily> netValueDailys)
		{
			foreach (var netValueDaily in netValueDailys)
			{
				UpdateNetValueDaily(netValueDaily);
			}
		}

		/// <summary>
		/// 根据基金编号删除每日净值
		/// </summary>
		/// <param name="fundId"></param>
		public static void DeleteNetValueDailyByFundId(Guid fundId)
		{
			NetValueDailyData.Instance.DeleteNetValueDaily(fundId);
		}

		/// <summary>
		/// 根据基金编号删除每日净值
		/// </summary>
		/// <param name="fundIds"></param>
		public static void DeleteNetValueDailysByFundId(IList<Guid> fundIds)
		{
			foreach (var fundId in fundIds)
			{
				DeleteNetValueDailyByFundId(fundId);
			}
		}

		/// <summary>
		/// 获取每日净值
		/// </summary>
		/// <param name="fundId"></param>
		/// <returns></returns>
		public static NetValueDaily GetNetValueDaily(Guid fundId)
		{
			return NetValueDailyData.Instance.GetNetValueDaily(fundId);
		}

		/// <summary>
		/// 分页获取每日净值
		/// </summary>
		/// <param name="pageIndex"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		public static IList<NetValueDaily> GetNetValueDailys(Int32 pageIndex, Int32 pageSize)
		{
			return NetValueDailyData.Instance.GetNetValueDailys(pageIndex, pageSize);
		}

		/// <summary>
		/// 获取所有每日净值
		/// </summary>
		/// <returns></returns>
		public static IList<NetValueDaily> GetAllNetValueDailys()
		{
			var list = (List<NetValueDaily>)NetValueDailyData.Instance.GetNetValueDailys(1, Int32.MaxValue);
			List<NetValueDaily> list1 = new List<NetValueDaily>();
			List<NetValueDaily> list2 = new List<NetValueDaily>();

			foreach (var item in list)
			{
				if (item.UnitNetValue != 0)
				{
					list1.Add(item);
				}
				else
				{
					list2.Add(item);
				}
			}

			list.Clear();
			list.AddRange(list1);
			list.AddRange(list2);
			return list;
		}
	}
}
